import { _decorator, Component, Node, ParticleSystem2D } from 'cc';
import { Item } from './Item';
import { MigaManager } from './MigaManager';
import { AudioManager } from '../../Scripts/Framework/Managers/AudioManager';
const { ccclass, property } = _decorator;

@ccclass('Firework')
export class Firework extends Item {

    @property(ParticleSystem2D)
    startParticle: ParticleSystem2D;

    @property(ParticleSystem2D)
    endParticle: ParticleSystem2D;

    isFire = false;

    Fire() {
        if (this.isFire) return;
        this.isFire = true;
        this.startParticle.resetSystem();
        AudioManager.Instance.PlaySFX(MigaManager.Instance.clips[0]);
        this.scheduleOnce(() => {
            this.startParticle.stopSystem();
            this.endParticle.resetSystem();
            this.sprite.enabled = false;
            AudioManager.Instance.PlaySFX(MigaManager.Instance.clips[1]);
            this.scheduleOnce(() => {
                this.isFire = false;
                this.sprite.enabled = true;
            }, 2);
        }, 3);
    }

}
